﻿using BasicInformation.API.Application.Command.OutsourcingCommand;
using BasicInformation.Infrastructure.Interface;
using MediatR;

namespace BasicInformation.API.Application.CommandHandler.OutsourcingCommandHandler
{
    public class OutsourcingBatchDeleteCommandHandler : IRequestHandler<OutsourcingBatchDeleteCommand, int>
    {
        private readonly IOutsourcingRepository outsourcingRepository;

        public OutsourcingBatchDeleteCommandHandler(IOutsourcingRepository outsourcingRepository)
        {
            this.outsourcingRepository = outsourcingRepository;
        }

        public async Task<int> Handle(OutsourcingBatchDeleteCommand request, CancellationToken cancellationToken)
        {
            var Id = request.Ids.Split(',').Select(int.Parse).ToArray();
            var list = await  outsourcingRepository.GetListInfo(x => Id.Contains(x.Id));
            foreach (var item in list)
            {
                item.IsDel=true;
            }
            return await outsourcingRepository.UpdateRange(list);
        }
    }
}
